<template>
            <el-card class="box-card">
            <el-table :data="tableData" stripe height="560">
                <el-table-column label="考生号" prop="userName" />
                <el-table-column label="家庭状况描述" prop="mark" align="left" show-overflow-tooltip/>
                <el-table-column label="困难证明材料" prop="imgUrl" align="center">
                <template v-slot="scope">
                    <el-button size="small" type="primary" icon="el-icon-picture" @click="check(scope.$index)">查看</el-button>
                </template>
                </el-table-column>
                <el-table-column label="操作" align="center" >
                    <template v-slot="scope">
                    <el-button size="small" type="success" icon="el-icon-check" @click="accept(scope.row.userName)">通过</el-button>
                    <el-button size="small" type="danger" icon="el-icon-close" @click="refuse(scope.row.userName)">拒绝</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-dialog v-model="dialogTableVisible" title="加载较慢，请耐心等待"  width="50%"  center>
                <el-image
                    style="width: 100%; height: 400px"
                    :src="url"
                    fit="cover"
                ></el-image>
                <template #footer>
                <el-button type="primary" @click="dialogTableVisible = false">确定</el-button>
                </template>
            </el-dialog>
            </el-card>
</template>

<script>
import {} from 'vue';
import request from '../../utils/request'
import { ElMessage } from 'element-plus';

export default {
	name: 'log',
	data() {
		return {
			tableData: [],
			dialogTableVisible: false,
			url: '',
			audit: {
				userName: '',
				flag: 0,
			}
		}
	},
	created() {
		this.getTable()
	},
	methods: {
		// 获取困难申请列表
		getTable() {
			request.post('/api/lesspay/list').then(res => {
				this.tableData = res.data;
			})
		},
		// 查看困难证明
		check(index) {
			this.url = this.tableData[index].imgUrl
			this.dialogTableVisible = true
		},
		accept(name) {
			this.audit.userName = name
			this.audit.flag = 1
			request.post('/api/lesspay/verify',this.audit).then(res => {
				if (res.code === 200) {
					ElMessage.success('审核成功！')
					this.getTable()
				} else {
					ElMessage.error('审核失败！')
				}
			})
		},
		refuse(name) {
			this.audit.userName = name
			this.audit.flag = -1
			request.post('/api/lesspay/verify',this.audit).then(res => {
				if (res.code === 200) {
					ElMessage.success('审核成功！')
					this.getTable()
				} else {
					ElMessage.error('审核失败！')
				}
			})
		},
	}
}
</script>

<style scoped>
.box-card {
    height: 100%;
}
</style>

